<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta content="user-scalable=no,width=device-width, initial-scale=1" id="viewport" name="viewport" initial-scale="1">

<script language="javascript" type="text/javascript" src="../js/js/baseJs.js"></script>

</head>
<body>

<div class="wap-upload-requirements" id="bankList" style="display: none;">
    <div class="wap-header">申请业务
        <a class="back" onClick="javascript:window.history.back();return false;"></a>
    </div>
    <div class="require-c-bd"> 
      <div class="info">
        <div class="l-c" v-if="businessName.indexOf('贷款')>=0">请在内容填写你的资产信息（比如房产，车子等等您的相关信息 ，我们会给你推荐对应的贷款）</div>
        <div class="l-c" v-if="businessName.indexOf('闲物')>=0">如果您有闲置物品，就可以来平台换取现金</div>
        <div class="l-c" v-if="businessName.indexOf('车险')>=0">您需要的保险险种？</div>
        <div class="l-c" v-if="businessName.indexOf('买房')>=0">买房说明</div>
      </div>
      <div class="l-input-group">
        <div class="select-wealth" v-if="businessName.indexOf('险')>=0">
          <div class="title">请选择：</div>
          <div class="r"> 
            <div class="select-c" :class="{on:insurance==this.selectInsurance}" v-for="insurance in insurances" @click="selectInsurances(insurance)">
                {{insurance}}
            </div>
          </div>
        </div>
        <div class="title-c" v-if="businessName.indexOf('险')<0"><div class="title">标题：</div><input placeholder="输入标题" v-model="businessName"></div>
        <div class="title-c"><div class="title">手机号：</div><input placeholder="输入联系手机" v-model="telephone" 
        onkeyup="this.value=this.value.replace(/\D/g,'')"></div>
        <div class="content-c" v-if="businessName.indexOf('贷款')<0 &&businessName.indexOf('险')<0  "><div class="title">内容：</div><textarea placeholder="输入需求内容" v-model="content"></textarea></div>
        
        <div class="select-wealth" v-if="businessName.indexOf('贷款')>=0">
          <div class="title">请选择：</div>
          <div class="r"> 
            <div class="select-c" :class="{on:isInSelectConetnt(wealth)}" v-for="wealth in wealths" @click="selectWealth(wealth)">
                {{wealth}}
            </div>
          </div>
          
        </div>
      </div>
    </div>
    <div class="wap-comfirm-button" @click="applyProjectItem()">确定申请</div>
</div>
<script src="../js/js/rem_fix.js"></script>
<script src="../js/js/common.js"></script>
<script type="text/javascript">
   var token=getCookie("userToken");
   var userId=getCookie("userId");
   var projectId=parseInt(window.location.hash.split("#")[1]) ;
   var loginUrl="../userBundle/login.mobile.html"+"?"+"../userBundle/baseUploadProject.mobile.html"+"#"+projectId;
   if(!token||!userId){
      window.location.href =loginUrl;
   }
  var bankListApp = new Vue({
      el: '#bankList', 
      data: {
         projectItems:'',
         businessName:"",
         content:"",
         telephone:"",
         isApplyProjectItem:false,
         wealths:["有商品房","有房子按揭","有私家车","有车子按揭","有单位社保","有公积金","有打卡工资","有商业保单","有定期存单","有股票等其他证券"],
         insurances:["车险","理财型分红险","大病险","意外险","大病意外险","婴幼儿险","公司财产保障险"],
         selectContent:[],
         selectInsurance:'',
      },
      ready:function(){
        $("#bankList").show();
        var url="/project/getProjectItems ";
        var data={id:projectId}
        pushData(url,data,function(res){
          console.log(res)
            if(res.state){
              this.projectItems=res.data.projectItems;
             // console.log(this.projectItems)
               if(this.projectItems[0]){
                  this.businessName=this.projectItems[0].businessName;
                }else{
                  alert("后台没有配置项目业务")
                }
            }else if(res.errorCode==008){
               window.location.href =url;
            }
            else{
              alert(res.message)
            }
            
        }.bind(this))

        
         
      }, 
      methods:{
        isInSelectConetnt:function(wealth){
          var isInSelectConetnt=false;
          for(var i=0;i<this.selectContent.length;i++){
            if(this.selectContent[i]==wealth){
              isInSelectConetnt=true;
            }
          }
          return isInSelectConetnt
        },
        selectWealth:function(wealth){
          if(this.isInSelectConetnt(wealth)){
             this.selectContent=_.without(this.selectContent, wealth);
          }else{
            this.selectContent.push(wealth);
          }
          
        },
        selectInsurances:function(insurance){
            this.selectInsurance=(insurance);
            
        },
        applyProjectItem:function(){
          if(this.isApplyProjectItem){
            return;
          }
          if(!this.telephone){
            alert("手机号必填")
            return;
          }
          this.isApplyProjectItem=true;
          var url="/project/applyProjectItem";
          this.content=this.selectContent.join(",");
          if(this.businessName.indexOf("险")>=0){
             this.content=this.selectInsurance;
          };
          var data={
              address: "无",
              client: 1,
              doc: this.content,
              payAccount: "无",
              payType: null,
              projectId:projectId,
              projectItemId: this.projectItems[0].id,
              telephone: this.telephone,
              token: token,
              userId: userId
            };
            pushData(url,data,function(res){
               if(res.state){
                alert("提交成功");
               }else if(res.errorCode==008){
                  window.location.href =loginUrl;
               }
               else{
                alert(res.message);
               }
            }.bind(this));
        }
      }
    })
</script>

</body>
</html>